package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhLeave;
import com.yinhe.system.service.IYhLeaveService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 休假记录Controller
 * 
 * @author yinhe
 * @date 2022-07-26
 */
@RestController
@RequestMapping("/system/leave")
public class YhLeaveController extends BaseController
{
    @Autowired
    private IYhLeaveService yhLeaveService;

    /**
     * 查询休假记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhLeave yhLeave)
    {
        startPage();
        List<YhLeave> list = yhLeaveService.selectYhLeaveList(yhLeave);
        return getDataTable(list);
    }

    /**
     * 导出休假记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:export')")
    @Log(title = "休假记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhLeave yhLeave)
    {
        List<YhLeave> list = yhLeaveService.selectYhLeaveList(yhLeave);
        ExcelUtil<YhLeave> util = new ExcelUtil<YhLeave>(YhLeave.class);
        util.exportExcel(response, list, "休假记录数据");
    }

    /**
     * 获取休假记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhLeaveService.selectYhLeaveById(id));
    }

    /**
     * 新增休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:leave:add')")
    @Log(title = "休假记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhLeave yhLeave)
    {
        return toAjax(yhLeaveService.insertYhLeave(yhLeave));
    }

    /**
     * 修改休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:leave:edit')")
    @Log(title = "休假记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhLeave yhLeave)
    {
        return toAjax(yhLeaveService.updateYhLeave(yhLeave));
    }

    /**
     * 删除休假记录
     */
    @PreAuthorize("@ss.hasPermi('system:leave:remove')")
    @Log(title = "休假记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhLeaveService.deleteYhLeaveByIds(ids));
    }
}
